<?
define('_VIEW_MODEL_','default');
require_once './init.php';
header("Content-type:text/vnd.wap.wml;charset=utf-8"); 
$id = intval($id);
$no = intval($auid);
$nid = intval($nid);
$noid = intval($noid);
$friend = "";
$tim = time();
//print_R($noinfo);
$rf = $db->Execute("select `title`,`link` from {$telper}friendlink where state = 0 order by rank desc");
$friendinfo = $rf ->GetArray();
foreach($friendinfo as $k=>$v){
	$friend .="<a href='$v[link]'>$v[title]</a>";
	$k = $k+1;
	if($k%4 ==0 && count($friend)%4 != 0){
		$friend .="<br/>";
	}
	if($k%4 !=0 && count($friendinfo)>$k){
		$friend .=".";
	}
}
if(isset($act)&&$act=="addcont"){
	$con = $content;
	$file = 'data/'.$id.'/'.$no.'/'.$nid.'/';
	$stat = mkdirExt($file);
	$fil = $file.$nid.".txt";
    if(file_exists($fil)){
    	$handle = fopen($fil,"a");
    	$con =htmlspecialchars($content);
    	$num = strlen($con);
    	//echo "update {$telper}novel set wordnum = wordnum+$num where id = $nid";
    	$db->Execute("update {$telper}chapter set wordnum = wordnum+$num where id = $noid");
    	$db->Execute("update {$telper}novel set wordnum = wordnum+$num where id = $nid");
    	$isd = fwrite($handle,$con);
    	fclose($handle);
    	header("Location:noveldetil.php?id=$id&auid=$no&nid=$nid");exit;
    }else{
    	$handle = fopen($fil,"wb");
    	$con =htmlspecialchars($content); 
    	$num = strlen($con);
    	$db->Execute("update {$telper}chapter set wordnum = wordnum+$num where id = $noid");
    	$db->Execute("update {$telper}novel set wordnum = wordnum+$num where id = $nid");
    	$isd = fwrite($handle,$con);
    	fclose($handle);
    	header("Location:noveldetil.php?id=$id&auid=$no&nid=$nid");exit;
    }
}
$smartyObj->assign("id",$id);
$smartyObj->assign("auid",$no);
$smartyObj->assign("nid",$nid);
$smartyObj->assign("noid",$noid);
$smartyObj->assign("time",$tim);
$smartyObj->display("addcont.tpl");
?>